<?php 
	if (!isset($_SESSION)){
		session_start();
	}

	$id = $_SESSION["id_pedido"];
	include_once "PedidosControl.php";
	include_once "Product.php";
	header("Content-Type: text/html; charset=UTF-8", true);
		
	
	$pedidoLista = PedidosControl::getPedidoById($id);
	foreach($pedidoLista as $pedido){
			//$p = $pedido->Product;
			if($pedido->Product->Fotos[0] != null){
			$file = "imagensBanco/photo".$pedido->Product->Id ."". $pedido->Product->Fotos[0][1];
			//echo $file;
			if(file_exists($file)) @unlink($file);
			$fp = fopen($file, "a");
			$escreve = fwrite($fp, $pedido->Product->Fotos[0][0]);
			fclose($fp);
			
		}
		else{
			$file = "imagensBanco/imagemIndisponivel.bmp";
		}
		$categorias = implode(', ', $pedido->Product->Categoria);
		//$pedido2->Product->Categoria
		echo"<tr class=\"row\">";
				echo"<td class=\"table-column description\"><span class=\"product-name\">" . $pedido->Product->Nome . "</span><span class=\"product-categories\">" . $categorias . "</span></td>";
				echo"<td class=\"table-column column-photo\"><img class=\"photo\" src=" . $file . "/></td>";
				echo "<td class=\"table-column amount\">" . $pedido->TotalAmount . "</td>";
				echo"<td class=\"table-column single-price\">" . $pedido->Product->UltimoPreco . "</td>";
				echo"<td class=\"table-column total-price\">" .  $pedido->TotalAmount*$pedido->Product->UltimoPreco . "</td>";
				echo"<td class=\"table-column track\"><input type=\"text\" value=" . $pedido->TrackingCode . " name=\"track\" ></td>";
		echo"</tr>";
	}
?>